﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MLM.AdminCP.Class;
using Telerik.Web.UI;
using MLM.Base;

namespace MLM.AdminCP.Pages
{
    public partial class ProductDescription : BasePage
    {
        protected override void OnInit(EventArgs e)
        {
            Permission.CheckIsAdmin();
            base.OnInit(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {            
            RadProductDescriptionGrid.ItemUpdated += new GridUpdatedEventHandler(radProductDescriptionGrid_ItemUpdated);
            RadProductDescriptionGrid.ItemInserted += new GridInsertedEventHandler(radProductDescriptionGrid_ItemInserted);
            RadProductDescriptionGrid.ItemDeleted += new GridDeletedEventHandler(radProductDescriptionGrid_ItemDeleted);
            RadProductDescriptionGrid.ItemCommand += new GridCommandEventHandler(RadProductDescriptionGrid_ItemCommand);
        }
        void RadProductDescriptionGrid_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.InitInsertCommandName)
            {
                e.Canceled = true;
                var newValues = new
                    System.Collections.Specialized.ListDictionary();
                newValues["IsDefault"] = false;
                e.Item.OwnerTableView.InsertItem(newValues);
            }
        }
        void radProductDescriptionGrid_ItemDeleted(object sender, GridDeletedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                Message.ShowError("ProductDescription " + e.Item["ProductDescriptionID"].Text + " cannot be deleted. Reason: " + e.Exception.Message);
            }
            else
            {
                Message.ShowSuccess("ProductDescription " + e.Item["ProductDescriptionID"].Text + " deleted!");
            }
        }

        void radProductDescriptionGrid_ItemInserted(object sender, GridInsertedEventArgs e)
        {
            if (e.Exception != null)
            {
                Message.ShowError("ProductDescription cannot be inserted. Reason: " + e.Exception.Message);
                e.ExceptionHandled = true;
                e.KeepInInsertMode = true;
            }
            else
            {
                Message.ShowSuccess("ProductDescription inserted!");
            }
        }

        void radProductDescriptionGrid_ItemUpdated(object sender, GridUpdatedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.KeepInEditMode = true;
                e.ExceptionHandled = true;
                Message.ShowError("ProductDescription " + e.Item["ProductDescriptionID"].Text + " cannot be updated. Reason: " + e.Exception.Message);
            }
            else
            {
                Message.ShowSuccess("ProductDescription " + e.Item["ProductDescriptionID"].Text + " updated.");
            }
        }  
    }
}